<template>
    <div class="goods-list">
        <!-- 使用标签跳转  router-link :to=-->
        
        <!-- 使用window.location.href的形式,叫做编程式导航 -->
        <!-- <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">¥{{item.sell_price}}</span>
                    <span class="old">¥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{item.stock_quantity}}套</span>
                </p>
            </div>
        </div> -->
        <div class="goods-item" @click="goDetail(1)">
            <img src="/static/images/muwu.jpg" alt="">
            <h1 class="title">木屋</h1>
            <div class="info">
                <p class="price">
                    <span class="now">¥170000</span>
                    <span class="old">¥190000</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余10套</span>
                </p>
            </div>
        </div>
        <div class="goods-item" @click="goDetail(2)">
            <img src="/static/images/shuijiao.jpg" alt="">
            <h1 class="title">猫咪</h1>
            <div class="info">
                <p class="price">
                    <span class="now">¥1700</span>
                    <span class="old">¥1900</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余6只</span>
                </p>
            </div>
        </div>
        <div class="goods-item" @click="goDetail(3)">
            <img src="/static/images/muwu.jpg" alt="">
            <h1 class="title">木屋</h1>
            <div class="info">
                <p class="price">
                    <span class="now">¥170000</span>
                    <span class="old">¥190000</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余10套</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    export default {
        data() {
            return {
                pageindex:1,//分页的页数
                goodsList : []
            }
        },
        created() {
    //         this.getGoodsList()
        },
        methods: {
            getGoodsList(){ //获取商品数据的方法
                this.$http.get('?pageindex='+this.pageindex).then(result=>{
                    if(result.body.status == 0){
                        this.goodsList = this.goodsList.concat(result.body.message);
                    }else{
                        Toast('获取商品数据失败')
                    }
                })
            },
            getMore(){
                this.pageindex++;
                this.getGoodsList();
            },
            goDetail(id){
                //使用js的形式进行路由导航
                //注意: 区分this.$route 参数属性 和 this.$router js操作
                //两种方式
                // this.$router.push('/home/goodsinfo/'+id);//方式一
                this.$router.push({name:'goodsinfo',params:{id}});//方式二,得在router.js中配置
            }
        }
    }
</script>

<style lang="scss" scoped>
    .goods-list{
        display: flex;
        flex-wrap: wrap;
        padding: 6px;
        justify-content: space-between; //两边对齐
        
        .goods-item{
            width: 49.5%; 
            border: 1px solid #ccc;//边框
            box-shadow: 0 0 8px #ccc; // 阴影
            margin: 3px 0;
            padding: 2px;
            display: flex;
            flex-direction: column; // 改变着重方向
            justify-content: space-between;
            min-height: 195px;//默认撑一个高度
            
            img{
                width: 100%;
            }

            .title{
                font-size: 14px;
            }
            .info{
                background-color: #eee;
                p{
                    margin: 0;  
                    padding: 3px;
                }
                .price{
                    .now{
                      color:red;
                      font-weight: bold; 
                      font-size: 16px; 
                    }
                    .old{
                        font-size: 12px; 
                        text-decoration: line-through;//划去线
                        margin-left: 10px;
                    }
                }
                .sell{
                    display: flex;
                    justify-content: space-between;
                    font-size: 12px;
                }
            }
        }
    }
</style>